package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IShoppingService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.NavListResponse;
import com.mall.shopping.dto.PanelListResponse;
import com.mall.user.annotation.Anoymous;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @description: 首页模块及所属商品显示，导航栏显示
 * @author: Woo
 * @create: 2021-08-25 10:28
 **/

@Slf4j
@RestController
@RequestMapping("/shopping")
@Anoymous
public class PanelController {

    @Reference(timeout = 3000, retries = 2, check = false)
    IShoppingService shoppingService;

    /**
     * 用于显示首页信息的controller
     *
     * @return
     */
    @GetMapping("/homepage")
    public ResponseData homePagePanel() {
        PanelListResponse response = shoppingService.homePageShow();
        if (response.getCode().equals(ShoppingRetCode.SUCCESS.getCode())) {
            return new ResponseUtil().setData(response.getPanelDtos());
        }
        return new ResponseUtil().setErrorMsg(response.getMsg());
    }

    /**
     * 用于显示导航栏的controller
     *
     * @return
     */
    @GetMapping("/navigation")
    public ResponseData navigationShow() {
        NavListResponse navListResponse = shoppingService.navListShow();
        if (navListResponse.getCode().equals(ShoppingRetCode.SUCCESS.getCode()))
            return new ResponseUtil().setData(navListResponse.getPannelContentDtos());
        return new ResponseUtil().setErrorMsg(navListResponse.getMsg());
    }

}
